<?php

namespace app\admin\model;
use app\common\model\Draw as DrawModel;
use app\common\model\MemberLevel as MemberLevelModel;
class Draw extends DrawModel
{

    /**
     * 获取抽奖列表
     * @param $orderby  排序
     * @param $limit    分页
     * @param $page     每页数量
     * @param array $where  查询条件
     * @return array
     * @throws \think\db\exception\DbException
     */
    public static function getList($orderby,$limit,$page,$where = []){
        $res = self::where($where)->order($orderby)->paginate(['list_rows'=>$limit,'page'=>$page])->toArray();
        $data = [];

        foreach ($res['data'] as $k => $v){
            $level = MemberLevelModel::getDetails($v['level_id']);
            $v['level_name'] = $level ? $level['name'] : '';
            $v['type_name'] = self::type_name($v['type']);

            $data[$k] = $v;
        }
        $res['data'] = $data;
        return $res;
    }
}